package com.itheima.ydd.controller;

import com.itheima.ydd.common.R;
import com.itheima.ydd.dto.PageInfo;
import com.itheima.ydd.pojo.YddLink;
import com.itheima.ydd.service.YddLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("ydd_link")
public class YddLinkController {

    @Autowired
    private YddLinkService yddLinkService;


    /**
     * 分页查询
     * @param type
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("list")
    public ResponseEntity<R<PageInfo<YddLink>>> findByPage(@RequestParam("type") String type,
                                                           @RequestParam("page") String page,
                                                           @RequestParam("limit") String limit){
       return yddLinkService.findByPage(type,page,limit);
    }

    /**添加有情链接
     *
     * @param yddLink
     * @return
     */
    @PostMapping("add")
    public ResponseEntity<R<String>> add(@RequestBody YddLink yddLink){
        return yddLinkService.add(yddLink);
    }

    /**
     * 删除友情链接
     * @param id
     * @return
     */
    @GetMapping("del")
    public ResponseEntity<R<String>> del(@RequestParam Integer id){
        return yddLinkService.del(id);
    }

    /**更新友情链接
     *
     * @param yddLink
     * @return
     */
    @PostMapping("update")
    public ResponseEntity<R<String>> update(@RequestBody YddLink yddLink){
        return yddLinkService.updateLink(yddLink);
    }

    @GetMapping("rowInfo")
    public ResponseEntity<R<YddLink>> rowInfo(@RequestParam Integer id){
        return yddLinkService.rowInfo(id);
    }


}
